cd "D:"
import excel "Data.xlsx", sheet("Data_FirEx") firstrow clear

*Data cleaning
label define Group 1 "1.无问责+积极结果（环保）" 2 "2.无问责+消极结果（环保）" 3 "3.问责+积极政策结果（环保）" 4"4.问责+消极策结果（环保）"
encode Group, gen(Group1) label(Group)

gen sanction = 1
replace sanction = 0 if Group1 == 1 | Group1 == 2

gen outcomes = 0
replace outcome = 1 if Group1 == 1 | Group1 == 3

label define eval1 1"非常不同意" 2"不同意" 3"既不同意也不反对" 4"同意" 5"非常同意"
label define eval2 1"非常不同意" 2"不同意" 3"既不同意也不反对" 4"同意" 5"非常同意"
label define eval3 1"非常不同意" 2"不同意" 3"既不同意也不反对" 4"同意" 5"非常同意"

encode eval1, gen(eval11) label(eval1)
encode eval2, gen(eval21) label(eval2)
encode eval3, gen(eval31) label(eval3)

encoder gender , replace setzero

label define age  1 "18-19岁" 2 "20-24岁" 3 "25-29岁" 4 "30-34岁" 5 "35-39岁" 6 "40-44岁" 7 "45-49岁" 8 "50-54岁" 9 "55-59岁" 10 "60岁以上"
encode age, gen(age1) label(age)

label define affiliation 0 "无业" 1 "全日制学生" 2 "党政机关" 3 "事业单位" 4 "国有企业" 5 "私营企业" 6 "外资企业" 7 "个体工商户" 8 "务农"  10"其他"  9"自由职业【提示：如作家、股票投资】"
encode affiliation , gen(affiliation1) label(affiliation)

label define politics 0 "群众" 1 "共青团员" 2 "中共党员" 3 "民主党派"
encode politics , gen(politics1) label(politics)

label define education 0 "小学及以下" 1 "初中" 2 "高中（含中专、技校、职高）" 3  "大专" 4   "大学本科" 5 "硕士" 6"博士"
encode education , gen(education1) label(education)

label define hukou 0 "农业户口" 1 "非农业户口" 2"没有户口"
encode hukou , gen(hukou1) label(hukou)

label define income 1 "5000元以下" 2 "5000-9999元" 3 "10,000-19,999元" 4 "20,000-29,999元" 5 "30,000-39,999元" 6 "40,000-49,999元" 7 "50,000-59,999元" 8 "60,000-79,999元" 9 "80,000-99,999元" 10 "100,000-119,999元" 11 "120,000-139,999元" 12 "140,000-159,999元" 13 "160,000-179,000元" 14 "180,000-199,999元" 15 "200,000-299,999元" 16"30万元以上"
encode income , gen(income1) label(income)

label define Ver1 0 "材料中没有相关的信息"  1 "进一步恶化" 2 "有明显改善"
encode Ver1 , gen(Ver11) label(Ver1)

label define Ver2 0 "材料中没有相关的信息" 1 "汉东省政府对南山市相关责任单位和责任人进行追责问责" 2 "汉东省政府向南山市派出督察组" 3 "汉东省政府要求各地落实生态优先、绿色发展的理念"
encode Ver2 , gen(Ver21) label(Ver2)

drop age affiliation education politics hukou income eval1 eval2 eval3 Ver1 Ver2 Group1
rename (age1 affiliation1 education1 politics1 hukou1 income1 eval11 eval21 eval31 Ver11 Ver21) (age affiliation education politics hukou income eval1 eval2 eval3 Ver1 Ver2)

gen eval = (eval1 + eval2 + eval3 ) / 3

norm eval, method(mmx)
norm satisf, method(mmx)

*Descriptive Statistics
foreach v of var gender age politics income affiliation hukou education{
	logout, save (table_`v') excel replace: tab `v'
}

*Balance check
foreach v of var gender age politics income affiliation hukou education{
	ttest `v', by (sanction)
	ttest `v', by (outcomes)
}

*Modeling
reg mmx_eval i.sanction i.outcomes
outreg2 using Resultsofexperiment1.xls, replace bdec(3) tdec(3) ctitle(eval) e(r2_a,F) addstat(F test,e(p)) alpha(0.001, 0.01, 0.05)

reg mmx_satisf i.sanction i.outcomes
outreg2 using Resultsofexperiment1.xls, append bdec(3) tdec(3) ctitle(satisf) e(r2_a,F) addstat(F test,e(p)) alpha(0.001, 0.01, 0.05)

reg mmx_eval i.sanction i.outcomes i.gender i.age i.politics i.income i.affiliation i.hukou i.education
outreg2 using Resultsofexperiment1.xls, append bdec(3) tdec(3) ctitle(eval) e(r2_a,F) addstat(F test,e(p)) alpha(0.001, 0.01, 0.05)

reg mmx_eval i.sanction##i.outcomes
outreg2 using Resultsofexperiment1.xls, append bdec(3) tdec(3) ctitle(eval) e(r2_a,F) addstat(F test,e(p)) alpha(0.001, 0.01, 0.05)

*Average treatment effect
foreach v of var sanction outcomes{
  su `v' if e(sample)
  local low_`v'=r(mean)-r(sd)
  local high_`v'=r(mean)+r(sd)
}

label define lab_sanction 0"without sanction" 1"with sanction"
label values sanction lab_sanction
label define lab_outcomes 0 "negative outcome" 1"positive outcome"
label values outcomes lab_outcomes

sum mmx_eval if sanction==0 & outcomes==0
sum mmx_eval if sanction==0 & outcomes==1
sum mmx_eval if sanction==1 & outcomes==0
sum mmx_eval if sanction==1 & outcomes==1

catcibar mmx_eval , over(sanction) by(outcomes) legend(position(6) rows(3)) ///
ytitle("Blame avoidance effect",size(mlarge)) wrapxlab(3) xlabel(none,noticks) xscale(off) ///
xsize(5) ysize(4) ///
xtitle(n=200		 ///
n=198		 ///
n=200		 ///
n=199) scheme( s1mono)
